//index.js
//获取应用实例
const app = getApp()
let Axios = require('../../../common/js/ajax.js'); //引入Axios方法
let Mtils = require('../../../common/js/Mtils.min.js');
Mtils = Mtils.Mtils
var page = 1;
var switch_p = true
Page({
	data: {
		openid: '',
		nickName: '',
		avatarUrl: '',
		curentNav: 2, //当前导航
		follow: [],
		isIpx:app.globalData.isIpx?true:false
	},
	//事件处理函数
	onLoad: function() {
		var _this = this
		this.load = this.selectComponent("#loading");
		this.uid = app.globalData.uid || ''
		this.Md5 = Mtils.security.hex_md5(this.uid) + app.globalData.secret;
		this.Md5 = Mtils.security.hex_md5(this.Md5);
		this.timesp = Mtils.now();
		Axios.get(app.globalData.baseUrl + 'App/User/UserInfo/collection_list', {
			uid: _this.uid,
			time: _this.timesp,
			sign: _this.Md5
		}, (res) => {
			console.log(res)
			if (res.status == 1) {
				var data = res.info
				_this.setData({
					follow: data
				})
				_this.load.loadIng()
			}
		})
	},
	onReady: function() {
		wx.setNavigationBarTitle({
			title: '我的关注'
		})
	},
	onReachBottom: function() {
		var _this = this;
		wx.showLoading({
			title: '玩命加载中',
		})
		if (switch_p) {
			switch_p = false
			page = page + 1;
			Axios.get(app.globalData.baseUrl + 'App/User/UserInfo/collection_list?p=' + page, {
				uid: _this.uid,
				time: _this.timesp,
				sign: _this.Md5
			}, (res) => {
				console.log(res)
				if (res.status == 1) {
					var data = res.info
					var temp = _this.data.follow.concat(data)
					_this.setData({
						follow: temp
					})
					switch_p = true
					wx.hideLoading();
				}
			})
		}
	},
	handleCancelTap: function(e) {
		var _this = this
		var index = e.currentTarget.dataset.index;
		var id = e.currentTarget.dataset.id;
		Axios.get(app.globalData.baseUrl + 'App/Store/Store/store_follow', {
			uid: _this.uid,
			time: _this.timesp,
			sign: _this.Md5,
			store_id: id,
			p: 1
		}, (res) => {
			console.log(res)
			if (res.status == 1) {
				var data = res.info
				var temp = _this.data.follow;
				temp.splice(index, 1)
				_this.setData({
					follow: temp
				})
			}
		})
	}
})
